package com.madzone.wiki.gae.ds.model;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance =
        JDOHelper.getPersistenceManagerFactory("transactions-optional");
    
    private static ThreadLocal<PersistenceManager> pm = new ThreadLocal<PersistenceManager>();

    private PMF() {}
    
    public static PersistenceManager getPM() {
    	PersistenceManager pmr = pm.get();
    	if (pmr == null || pmr.isClosed()) {
    		pmr = pmfInstance.getPersistenceManager();
    		pm.set(pmr);
    	}
    	return pmr;
    }
}
